package cn.mccraft.uide.api.ui;

import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ResourceBundle;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

public interface Controller {
	
	default Parent init(URL url, ResourceBundle bundle) throws IOException{
		FXMLLoader loader = new FXMLLoader(url);
		loader.setRoot(this);
		loader.setController(this);
		loader.setCharset(StandardCharsets.UTF_8);
		if(bundle != null) {
			loader.setResources(bundle);
		}
		return loader.load();
	}

	default Parent init(String name, ResourceBundle bundle) throws IOException {
		return init(this.getClass().getResource("/" + name + ".fxml"), bundle);
	}
}
